//
//  NSDate+ToString.m
//  Utils
//
//  Created by enghou on 2018/1/20.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "NSDate+ToString.h"

@implementation NSDate (ToString)

-(NSString *)dateStr{
    return [self dateStrWithFormat:@"yyyy.MM.dd HH:mm:ss"];
}

-(NSString *)dateLineStr{
    
    return [self dateStrWithFormat:@"yyyy-MM-dd HH:mm:ss"];
}

-(NSString *)dateStrOnlyYearAndMonth{
    return [self dateStrWithFormat:@"yyyy-MM"];
}

-(NSString *)dateStrWithYearMonthDay{
    return [self dateStrWithFormat:@"yyyy年MM月dd日"];
}

-(NSString *)dateLineStrOnlyDay{
    return [self dateStrWithFormat:@"yyyy-MM-dd"];
}

-(NSString *)dateStrWithFormat:(NSString *)format{
    if ([format length] == 0) {
        return nil;
    }
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    formatter.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];
    formatter.dateFormat = format;
    NSString *dateStr = [formatter stringFromDate:self];
    return dateStr;
}

@end
